<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>bzip2 文件二进制安全地读取</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.bzopen.html">« bzopen</a></li>
      <li style="float: right;"><a href="function.bzwrite.html">bzwrite »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.bzip2.html">Bzip2 函数</a></li>
    <li>bzip2 文件二进制安全地读取</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.bzread" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">bzread</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">bzread</span> &mdash; <span class="dc-title">bzip2 文件二进制安全地读取</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.bzread-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>bzread</strong></span>(<span class="methodparam"><span class="type">resource</span> <code class="parameter">$bz</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$length</code><span class="initializer"> = 1024</span></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>bzread()</strong></span> 从指定的 bzip2 文件指针中读取数据。
  </p>
  <p class="para">
    读取到 <code class="parameter">length</code>（未经压缩的长度）个字节，或者到文件尾，取决于先到哪个。
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.bzread-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">bz</code></dt>

     <dd>

      <p class="para">
       文件指针。它必须是有效的并且指向 <span class="function"><a href="function.bzopen.html" class="function">bzopen()</a></span> 成功打开的文件。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">length</code></dt>

     <dd>

      <p class="para">
       如果没有提供， <span class="function"><strong>bzread()</strong></span> 一次会读入 1024 个字节（未经压缩的长度）。
       一次最大可读入 8192 个未压缩的字节。
      </p>
     </dd>

    
   </dl>

  </p> 
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.bzread-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回解压的数据，在错误时返回 <strong><code>false</code></strong>。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.bzread-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-708">
    <p><strong>示例 #1 <span class="function"><strong>bzread()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"/tmp/foo.bz2"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$bz&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">bzopen</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"r"</span><span style="color: #007700">)&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Couldn't&nbsp;open&nbsp;</span><span style="color: #0000BB">$file</span><span style="color: #DD0000">"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$decompressed_file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">;<br />while&nbsp;(!</span><span style="color: #0000BB">feof</span><span style="color: #007700">(</span><span style="color: #0000BB">$bz</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$decompressed_file&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #0000BB">bzread</span><span style="color: #007700">(</span><span style="color: #0000BB">$bz</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4096</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">bzclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$bz</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"The&nbsp;contents&nbsp;of&nbsp;</span><span style="color: #0000BB">$file</span><span style="color: #DD0000">&nbsp;are:&nbsp;&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">$decompressed_file</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.bzread-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.bzwrite.html" class="function" rel="rdfs-seeAlso">bzwrite()</a> - 二进制安全地写入 bzip2 文件</span></li>
    <li class="member"><span class="function"><a href="function.feof.html" class="function" rel="rdfs-seeAlso">feof()</a> - 测试文件指针是否到了文件结束的位置</span></li>
    <li class="member"><span class="function"><a href="function.bzopen.html" class="function" rel="rdfs-seeAlso">bzopen()</a> - 打开 bzip2 压缩文件</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>